unit ServerSet;

interface
{$WARNINGS OFF} //FileCtrl has a warn
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxLookAndFeels, cxLookAndFeelPainters, Menus, FileCtrl,
  cxControls, cxContainer, cxEdit, dxSkinsCore, dxSkinsDefaultPainters, IniFiles,
  cxLabel, cxSpinEdit, cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls,
  cxButtons;
{$WARNINGS ON}
type
  TfrmServerSet = class(TForm)
    btnOK: TcxButton;
    edtDefDataPath: TcxButtonEdit;
    btnCancel: TcxButton;
    edtServerPort: TcxSpinEdit;
    cxLabel1: TcxLabel;
    cxLabel2: TcxLabel;
    cxLabel3: TcxLabel;
    edtFPTPort: TcxSpinEdit;
    edtEMServerPort: TcxSpinEdit;
    cxLabel4: TcxLabel;
    procedure edtDefDataPathPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmServerSet: TfrmServerSet;

implementation

uses ServerGlobal;

{$R *.dfm}

procedure TfrmServerSet.edtDefDataPathPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
var
  sDBDir: string;
begin
  sDBDir := edtDefDataPath.Text;
  if SelectDirectory(sDBDir, [sdAllowCreate, sdPerformCreate, sdPrompt], 1000) then
    edtDefDataPath.Text := sDBDir;
end;

procedure TfrmServerSet.FormCreate(Sender: TObject);
var
  serverIni: TIniFile;
begin
  if FileExists(ExtractFilePath(Application.ExeName) + g_ServerIni) then
  begin
    serverIni := TIniFile.Create(ExtractFilePath(Application.ExeName) + g_ServerIni);
    try
      g_Auth := serverIni.ReadString('DataBase', 'Auth', 'auServer');
      g_DataBaseUser := serverIni.ReadString('DataBase', 'User', '');
      g_DataBasePwd := serverIni.ReadString('DataBase', 'Pwd', '');
      if g_ServerDefPort = 5050 then
        g_YbServerPort := serverIni.ReadInteger('ServerSet', 'ServerPort', g_ServerDefPort)
      else if g_ServerDefPort = 5030 then
        g_YbServerPort := serverIni.ReadInteger('ServerSet', 'C3ServerPort', g_ServerDefPort)
      else if g_ServerDefPort = 5010 then
        g_YbServerPort := serverIni.ReadInteger('ServerSet', 'CWServerPort', g_ServerDefPort);
      g_FTPPort := serverIni.ReadInteger('ServerSet', 'FTPPort', 5021);
      g_EMPort := serverIni.ReadInteger('ServerSet', 'EMPort', 5022);
      g_DataBaseSavePath := serverIni.ReadString('ServerSet', 'DefDataPath', ExtractFilePath(Application.ExeName) + 'Data\');
      g_DataBaseSavePath := UpperCase(g_DataBaseSavePath);
      if Copy(g_DataBaseSavePath, Length(g_DataBaseSavePath), 1) <> '\' then
        g_DataBaseSavePath := g_DataBaseSavePath + '\';
    finally
      FreeAndNil(serverIni);
    end;
  end;
  edtServerPort.Value := g_YbServerPort;
  edtEMServerPort.Value := g_EMPort;  
  edtDefDataPath.Text := g_DataBaseSavePath;
end;

end.

